var events=require('events');
var util=require('util');   //核心库之一，工具包

//javascript类的写法
var Person=function(name){
    this.name=name;
}

util.inherits(Person,events.EventEmitter);

var xiaoming=new Person('xiaoming');
var lily=new Person('lily');
var lucy=new Person('lucy');

var persons=[xiaoming,lily,lucy];

//循环绑定事件
persons.forEach(function(persons){
    persons.on('speak',function(msg){
        console.log(persons.name+" said :"+msg);
    })
})

xiaoming.emit('speak','hi');
lucy.emit('speak','i want you!');
//  var myEmitter=new events.EventEmitter();

//  myEmitter.on('someEvent',function(msg){
//      console.log(msg);
//  })

//  myEmitter.emit('someEvent',"the event was emitted....");